package com.java.demo.service;

import com.java.demo.dao.UserRepository;
import com.java.demo.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-07-22
 * Time: 8:42
 */
@Service
public class UserService {
    //属性注入
    //@Autowired
    @Resource
    private UserRepository aaa;//这里是依赖注入,从Spring当种找到UserRepository赋值给新的变量
    public int add(){
        System.out.println("执行UserService方法");
        //传统写法
        /*UserRepository userRepository=new UserRepository();
        return userRepository.add();*/
        //Spring写法
        //依赖查找
       /* ApplicationContext context=new
                ClassPathXmlApplicationContext("spring-config.xml");
        UserRepository userRepository=context.getBean("userRepository",UserRepository.class);
        return userRepository.add();*/
        return aaa.add();
    }
}
